$(document).ready(function () {
    let id =getUrlString("id");
    let obj=new Object();
    obj.m="getMerchantById";
    obj.id=id;
    //初始化商品类型
    $.ajax({
        //请求方式 同步false 异步true
        async:true,
        //请求方式
        type:"POST",
        //请求地址
        url:basePath+"/api/mechandise",
        //返回值类型
        data:obj,
        dataType:"json",
        //成功之后的回调函数
        success:function (result) {
            initMerchantInfo(result);
        },
        //请求失败，包含具体的错误信息
        error:function (e) {
            console.log(e.status);
            console.log(e.responseText);
        }
    });
});
//初始化商品信息
function initMerchantInfo(result) {
    console.log(result);
    $(".detail").html("");
    let img =$("<img>").attr("src","/resources"+result.picture);
    let span1 =$("<span></span>").text("商品类别"+result.category);
    let br1=$("<br>");

    let span2 =$("<span></span>").text("商品名称"+result.merName);
    let br2=$("<br>");

    let span3 =$("<span></span>").text("商品型号"+result.merModel);
    let br3=$("<br>");

    let span4 =$("<span></span>").text("市场价 ￥："+result.price);
    let br4=$("<br>");

    let span5 =null;
    let br5=null;
    if(result.special==1){
        let span5 =$("<span></span>").text("特价 ￥："+result.sprice);
        let br5=$("<br>");
    }

    let span6 =$("<span></span>").text("生产厂家："+result.manufacturer);
    let br6=$("<br>");
    let span7 =$("<span></span>").text("生产日期："+result.leaveFactoryDate);
    let br7=$("<br>");

    let span8 =$("<span></span>").text("商品描述："+result.merDesc);
    $(".detail").append(img,span1,br1,span2,br2,span3,br3,span4,br4,span5,br5,span6,br6,span7,br7,span8);
    
}